#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Predesys Server - User Interface - Service types management 
@version: 0.2.5
@license: GPL 3.0 (see "license" file)
@author: Jose A. Jimenez
@contact: jajimc@gmail.com"""

import sys
sys.dont_write_bytecode = True
import os
import os.path
DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(os.path.join(DIR, "../core"))
import exceptions
import usage
import tools
import services
    
def manageArgs(argc, argv):
    """Manages command line input.
    @param argc: Command line argument count
    @type argc: C{int}
    @param argv: Command line input data
    @type argv: C{list}"""
    if argc == 3 and sys.argv[2] == "list":
        print_service_type_list()
    elif argc == 4 and sys.argv[2] == "data":
        print_service_type_data(sys.argv[3])
    else:
        print usage.get_usage()
        
def print_service_type_list():
    """Prints the ID of every service type."""
    serviceTypeList = services.get_service_types()
    for serviceTypeId in serviceTypeList:
        print serviceTypeId
        
def print_service_type_data(id):
    """Prints all fields of a service type.
    @param id: Service type ID
    @type id: C{str}"""
    serviceTypeData = services.get_service_type_data(id)
    print "ID: %s" % serviceTypeData.get_id()
            
    name = serviceTypeData.get_name()
    if name == None or name == "": name = "<None>"
    print "NAME: %s" % name
